﻿/**  PACS v1.0
* JC_MachineInfo.cs
*
* 类 名： JC_MachineInfo
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:29   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:JC_MachineInfo
	/// </summary>
	public partial class JC_MachineInfo
	{
		public JC_MachineInfo()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from JC_MachineInfo");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.JC_MachineInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.SheBeiChangJia != null)
			{
				strSql1.Append("SheBeiChangJia,");
				strSql2.Append("'"+model.SheBeiChangJia+"',");
			}
			if (model.SheBeiLeiXing != null)
			{
				strSql1.Append("SheBeiLeiXing,");
				strSql2.Append("'"+model.SheBeiLeiXing+"',");
			}
			if (model.SheBeiXingHao != null)
			{
				strSql1.Append("SheBeiXingHao,");
				strSql2.Append("'"+model.SheBeiXingHao+"',");
			}
			if (model.ShengChanPiCi != null)
			{
				strSql1.Append("ShengChanPiCi,");
				strSql2.Append("'"+model.ShengChanPiCi+"',");
			}
			if (model.SheBeiMingCheng != null)
			{
				strSql1.Append("SheBeiMingCheng,");
				strSql2.Append("'"+model.SheBeiMingCheng+"',");
			}
			if (model.ChuangJianShiJian != null)
			{
				strSql1.Append("ChuangJianShiJian,");
				strSql2.Append("'"+model.ChuangJianShiJian+"',");
			}
			if (model.ChuangJianRen != null)
			{
				strSql1.Append("ChuangJianRen,");
				strSql2.Append("'"+model.ChuangJianRen+"',");
			}
			if (model.CaiGouShiJian != null)
			{
				strSql1.Append("CaiGouShiJian,");
				strSql2.Append("'"+model.CaiGouShiJian+"',");
			}
			if (model.ChuangJianRenNO != null)
			{
				strSql1.Append("ChuangJianRenNO,");
				strSql2.Append("'"+model.ChuangJianRenNO+"',");
			}
			if (model.ChuangJianRenID != null)
			{
				strSql1.Append("ChuangJianRenID,");
				strSql2.Append("'"+model.ChuangJianRenID+"',");
			}
			if (model.KeYongBiaoShi != null)
			{
				strSql1.Append("KeYongBiaoShi,");
				strSql2.Append("'"+model.KeYongBiaoShi+"',");
			}
			if (model.BenDiAE != null)
			{
				strSql1.Append("BenDiAE,");
				strSql2.Append("'"+model.BenDiAE+"',");
			}
			if (model.FuWuAE != null)
			{
				strSql1.Append("FuWuAE,");
				strSql2.Append("'"+model.FuWuAE+"',");
			}
			if (model.SheBeiShouQuanMa != null)
			{
				strSql1.Append("SheBeiShouQuanMa,");
				strSql2.Append("'"+model.SheBeiShouQuanMa+"',");
			}
			if (model.DaYinJiIP != null)
			{
				strSql1.Append("DaYinJiIP,");
				strSql2.Append("'"+model.DaYinJiIP+"',");
			}
			if (model.SheBeiIP != null)
			{
				strSql1.Append("SheBeiIP,");
				strSql2.Append("'"+model.SheBeiIP+"',");
			}
			if (model.SheBeiDuanKou != null)
			{
				strSql1.Append("SheBeiDuanKou,");
				strSql2.Append("'"+model.SheBeiDuanKou+"',");
			}
			if (model.JieXiID != null)
			{
				strSql1.Append("JieXiID,");
				strSql2.Append("'"+model.JieXiID+"',");
			}
			if (model.DaYinJiPort != null)
			{
				strSql1.Append("DaYinJiPort,");
				strSql2.Append("'"+model.DaYinJiPort+"',");
			}
			if (model.JiGouBianMa != null)
			{
				strSql1.Append("JiGouBianMa,");
				strSql2.Append("'"+model.JiGouBianMa+"',");
			}
			if (model.JiGouID != null)
			{
				strSql1.Append("JiGouID,");
				strSql2.Append("'"+model.JiGouID+"',");
			}
			strSql.Append("insert into JC_MachineInfo(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.JC_MachineInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JC_MachineInfo set ");
			if (model.SheBeiChangJia != null)
			{
				strSql.Append("SheBeiChangJia='"+model.SheBeiChangJia+"',");
			}
			else
			{
				strSql.Append("SheBeiChangJia= null ,");
			}
			if (model.SheBeiLeiXing != null)
			{
				strSql.Append("SheBeiLeiXing='"+model.SheBeiLeiXing+"',");
			}
			else
			{
				strSql.Append("SheBeiLeiXing= null ,");
			}
			if (model.SheBeiXingHao != null)
			{
				strSql.Append("SheBeiXingHao='"+model.SheBeiXingHao+"',");
			}
			else
			{
				strSql.Append("SheBeiXingHao= null ,");
			}
			if (model.ShengChanPiCi != null)
			{
				strSql.Append("ShengChanPiCi='"+model.ShengChanPiCi+"',");
			}
			else
			{
				strSql.Append("ShengChanPiCi= null ,");
			}
			if (model.SheBeiMingCheng != null)
			{
				strSql.Append("SheBeiMingCheng='"+model.SheBeiMingCheng+"',");
			}
			else
			{
				strSql.Append("SheBeiMingCheng= null ,");
			}
			if (model.ChuangJianShiJian != null)
			{
				strSql.Append("ChuangJianShiJian='"+model.ChuangJianShiJian+"',");
			}
			else
			{
				strSql.Append("ChuangJianShiJian= null ,");
			}
			if (model.ChuangJianRen != null)
			{
				strSql.Append("ChuangJianRen='"+model.ChuangJianRen+"',");
			}
			else
			{
				strSql.Append("ChuangJianRen= null ,");
			}
			if (model.CaiGouShiJian != null)
			{
				strSql.Append("CaiGouShiJian='"+model.CaiGouShiJian+"',");
			}
			else
			{
				strSql.Append("CaiGouShiJian= null ,");
			}
			if (model.ChuangJianRenNO != null)
			{
				strSql.Append("ChuangJianRenNO='"+model.ChuangJianRenNO+"',");
			}
			else
			{
				strSql.Append("ChuangJianRenNO= null ,");
			}
			if (model.ChuangJianRenID != null)
			{
				strSql.Append("ChuangJianRenID='"+model.ChuangJianRenID+"',");
			}
			else
			{
				strSql.Append("ChuangJianRenID= null ,");
			}
			if (model.KeYongBiaoShi != null)
			{
				strSql.Append("KeYongBiaoShi='"+model.KeYongBiaoShi+"',");
			}
			else
			{
				strSql.Append("KeYongBiaoShi= null ,");
			}
			if (model.BenDiAE != null)
			{
				strSql.Append("BenDiAE='"+model.BenDiAE+"',");
			}
			else
			{
				strSql.Append("BenDiAE= null ,");
			}
			if (model.FuWuAE != null)
			{
				strSql.Append("FuWuAE='"+model.FuWuAE+"',");
			}
			else
			{
				strSql.Append("FuWuAE= null ,");
			}
			if (model.SheBeiShouQuanMa != null)
			{
				strSql.Append("SheBeiShouQuanMa='"+model.SheBeiShouQuanMa+"',");
			}
			else
			{
				strSql.Append("SheBeiShouQuanMa= null ,");
			}
			if (model.DaYinJiIP != null)
			{
				strSql.Append("DaYinJiIP='"+model.DaYinJiIP+"',");
			}
			else
			{
				strSql.Append("DaYinJiIP= null ,");
			}
			if (model.SheBeiIP != null)
			{
				strSql.Append("SheBeiIP='"+model.SheBeiIP+"',");
			}
			else
			{
				strSql.Append("SheBeiIP= null ,");
			}
			if (model.SheBeiDuanKou != null)
			{
				strSql.Append("SheBeiDuanKou='"+model.SheBeiDuanKou+"',");
			}
			else
			{
				strSql.Append("SheBeiDuanKou= null ,");
			}
			if (model.JieXiID != null)
			{
				strSql.Append("JieXiID='"+model.JieXiID+"',");
			}
			else
			{
				strSql.Append("JieXiID= null ,");
			}
			if (model.DaYinJiPort != null)
			{
				strSql.Append("DaYinJiPort='"+model.DaYinJiPort+"',");
			}
			else
			{
				strSql.Append("DaYinJiPort= null ,");
			}
			if (model.JiGouBianMa != null)
			{
				strSql.Append("JiGouBianMa='"+model.JiGouBianMa+"',");
			}
			else
			{
				strSql.Append("JiGouBianMa= null ,");
			}
			if (model.JiGouID != null)
			{
				strSql.Append("JiGouID='"+model.JiGouID+"',");
			}
			else
			{
				strSql.Append("JiGouID= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ID='"+ model.ID+"' ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_MachineInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_MachineInfo ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_MachineInfo GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,SheBeiChangJia,SheBeiLeiXing,SheBeiXingHao,ShengChanPiCi,SheBeiMingCheng,ChuangJianShiJian,ChuangJianRen,CaiGouShiJian,ChuangJianRenNO,ChuangJianRenID,KeYongBiaoShi,BenDiAE,FuWuAE,SheBeiShouQuanMa,DaYinJiIP,SheBeiIP,SheBeiDuanKou,JieXiID,DaYinJiPort,JiGouBianMa,JiGouID ");
			strSql.Append(" from JC_MachineInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			Pacs.Model.JC_MachineInfo model=new Pacs.Model.JC_MachineInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_MachineInfo DataRowToModel(DataRow row)
		{
			Pacs.Model.JC_MachineInfo model=new Pacs.Model.JC_MachineInfo();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["SheBeiChangJia"]!=null)
				{
					model.SheBeiChangJia=row["SheBeiChangJia"].ToString();
				}
				if(row["SheBeiLeiXing"]!=null)
				{
					model.SheBeiLeiXing=row["SheBeiLeiXing"].ToString();
				}
				if(row["SheBeiXingHao"]!=null)
				{
					model.SheBeiXingHao=row["SheBeiXingHao"].ToString();
				}
				if(row["ShengChanPiCi"]!=null)
				{
					model.ShengChanPiCi=row["ShengChanPiCi"].ToString();
				}
				if(row["SheBeiMingCheng"]!=null)
				{
					model.SheBeiMingCheng=row["SheBeiMingCheng"].ToString();
				}
				if(row["ChuangJianShiJian"]!=null && row["ChuangJianShiJian"].ToString()!="")
				{
					model.ChuangJianShiJian=DateTime.Parse(row["ChuangJianShiJian"].ToString());
				}
				if(row["ChuangJianRen"]!=null)
				{
					model.ChuangJianRen=row["ChuangJianRen"].ToString();
				}
				if(row["CaiGouShiJian"]!=null && row["CaiGouShiJian"].ToString()!="")
				{
					model.CaiGouShiJian=DateTime.Parse(row["CaiGouShiJian"].ToString());
				}
				if(row["ChuangJianRenNO"]!=null)
				{
					model.ChuangJianRenNO=row["ChuangJianRenNO"].ToString();
				}
				if(row["ChuangJianRenID"]!=null)
				{
					model.ChuangJianRenID=row["ChuangJianRenID"].ToString();
				}
				if(row["KeYongBiaoShi"]!=null)
				{
					model.KeYongBiaoShi=row["KeYongBiaoShi"].ToString();
				}
				if(row["BenDiAE"]!=null)
				{
					model.BenDiAE=row["BenDiAE"].ToString();
				}
				if(row["FuWuAE"]!=null)
				{
					model.FuWuAE=row["FuWuAE"].ToString();
				}
				if(row["SheBeiShouQuanMa"]!=null)
				{
					model.SheBeiShouQuanMa=row["SheBeiShouQuanMa"].ToString();
				}
				if(row["DaYinJiIP"]!=null)
				{
					model.DaYinJiIP=row["DaYinJiIP"].ToString();
				}
				if(row["SheBeiIP"]!=null)
				{
					model.SheBeiIP=row["SheBeiIP"].ToString();
				}
				if(row["SheBeiDuanKou"]!=null)
				{
					model.SheBeiDuanKou=row["SheBeiDuanKou"].ToString();
				}
				if(row["JieXiID"]!=null)
				{
					model.JieXiID=row["JieXiID"].ToString();
				}
				if(row["DaYinJiPort"]!=null)
				{
					model.DaYinJiPort=row["DaYinJiPort"].ToString();
				}
				if(row["JiGouBianMa"]!=null)
				{
					model.JiGouBianMa=row["JiGouBianMa"].ToString();
				}
				if(row["JiGouID"]!=null)
				{
					model.JiGouID=row["JiGouID"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,SheBeiChangJia,SheBeiLeiXing,SheBeiXingHao,ShengChanPiCi,SheBeiMingCheng,ChuangJianShiJian,ChuangJianRen,CaiGouShiJian,ChuangJianRenNO,ChuangJianRenID,KeYongBiaoShi,BenDiAE,FuWuAE,SheBeiShouQuanMa,DaYinJiIP,SheBeiIP,SheBeiDuanKou,JieXiID,DaYinJiPort,JiGouBianMa,JiGouID ");
			strSql.Append(" FROM JC_MachineInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,SheBeiChangJia,SheBeiLeiXing,SheBeiXingHao,ShengChanPiCi,SheBeiMingCheng,ChuangJianShiJian,ChuangJianRen,CaiGouShiJian,ChuangJianRenNO,ChuangJianRenID,KeYongBiaoShi,BenDiAE,FuWuAE,SheBeiShouQuanMa,DaYinJiIP,SheBeiIP,SheBeiDuanKou,JieXiID,DaYinJiPort,JiGouBianMa,JiGouID ");
			strSql.Append(" FROM JC_MachineInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JC_MachineInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from JC_MachineInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

